//
//  SecondViewController.m
//  07-Delegate.Block
//
//  Created by Snow on 16/7/22.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "SecondViewController.h"
#import "FirstViewController.h"
@interface SecondViewController ()
@property (nonatomic, strong) UITextField *text;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.text = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, 200, 30)];
    self.text.backgroundColor = [UIColor redColor];
    self.text.text = self.titleNsstring;
    [self.view addSubview:self.text];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 120, 200, 30);
    button.backgroundColor = [UIColor greenColor];
    [button setTitle:@"点击回到上一页" forState:UIControlStateNormal];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    NSLog(@"%@", );
}
- (void)handleButton:(UIButton *)button
{
//    NSInteger count = self.navigationController.viewControllers.count;
//    FirstViewController *first = self.navigationController.viewControllers[count - 2];
//    first.titleTextfield = _text.text;
#warning 触发协议方法(判断delegate存不存在 判断签订delegate的类有没有实现协议方法)
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValue:)]) {
        
        [self.delegate passValue:_text.text];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
